package com.jackeys.piaems.intrusionDetection;


import com.jackeys.piaems.dao.ImageDao;
import com.jackeys.piaems.dao.impl.ImageDaoImpl;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @ClassName: ImageServer
 * @Description: 图片服务器
 * @Author: Jackeys
 * @Date: 2021-06-28 17:32
 * @Version: 1.0
 */
@Slf4j
public class ImageServer implements Runnable{
    /**
     *
     */
    private static final long serialVersionUID = 2839564863495205814L;
    private ImageDao imageDao;
    ServerSocket ss;

    public ImageServer(ImageDao imageDao) throws Exception {
        //监听端口
        ss = new ServerSocket(9099);
        this.imageDao=imageDao;
        new Thread(this).start();
    }

    @Override
    public void run() {
        int i = 0;
        log.debug("入侵检测已启动");
        while (true) {
            try {
                Socket s = ss.accept();
                log.debug("=====================================================================");
                log.debug("接受到客户端请求");
                // 每个客户端一个处理线程
                new Handler(s, i,imageDao).start();
                i++;
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
